<template>
  <div>
    <div
      class="fly-home fly-panel"
      style="background-image: url()"
      v-for="(item, index) in user"
      :key="'user' + index"
    >
      <img :src="item.pic" alt="" />
      <i class="iconfont icon-renzheng" title="Imooc社区认证"></i>
      <h1>
        {{ item.name }}
        <i class="iconfont icon-nan"></i>
        <i
          class="layui-badge fly-badge-vip"
          v-if="item.isVip != '0' ? item.isVip : false"
          >VIP{{ item.isVip }}</i
        >
        <div v-for="(role, index) in item.roles" :key="'roles' + index">
          <span style="color: #c00" v-if="role === 'admin'">（管理员）</span>
          <span style="color: #5fb878" v-if="role === 'active'"
            >（社区之光）</span
          >
          <span v-if="role === 'xx'">（该号已被封）</span>
        </div>
      </h1>

      <p
        style="padding: 10px 0; color: #5fb878"
        v-if="item.regmark != '' ? item.regmark : false"
      >
        {{ item.regmark }}
      </p>

      <p class="fly-home-info">
        <i class="iconfont icon-kiss" title="飞吻"></i
        ><span style="color: #ff7200">{{ item.favs }}</span>
        <i class="iconfont icon-shijian"></i
        ><span>{{ item.created | moment }} 加入</span>
        <i class="iconfont icon-chengshi"></i>
        <span>来自{{ item.location ? item.location : '太空' }}</span>
      </p>
      <p class="fly-home-sign">（人生仿若一场修行）</p>
      <div class="fly-sns" data-user="">
        <a
          href="javascript:;"
          class="layui-btn layui-btn-primary fly-imActive"
          data-type="addFriend"
          >加为好友</a
        >
        <a
          href="javascript:;"
          class="layui-btn layui-btn-normal fly-imActive"
          data-type="chat"
          >发起会话</a
        >
      </div>
    </div>
    <div class="layui-container">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md6 fly-home-jie">
          <div class="fly-panel">
            <h3 class="fly-panel-title">他最近的提问</h3>
            <ul class="jie-row">
              <li v-for="(item, index) in lists" :key="'list' + index">
                <span class="fly-jing">精</span>
                <router-link
                  class="jie-title"
                  :to="{ name: 'detail', params: { tid: item._id } }"
                  >{{ item.title }}</router-link
                >
                <i>{{ item.created | moment }}</i>
                <em class="layui-hide-xs"
                  >{{ item.reads }}阅/{{ item.answer }}答</em
                >
              </li>
              <div
                v-if="lists.length === 0"
                class="fly-none"
                style="min-height: 50px; padding: 30px 0; height: auto"
              >
                <i style="font-size: 14px">没有发表任何求解</i>
              </div>
            </ul>
          </div>
        </div>
        <div class="layui-col-md6 fly-home-da">
          <div class="fly-panel">
            <h3 class="fly-panel-title">他最近的回答</h3>
            <ul class="home-jieda">
              <li v-for="(item, index) in comm" :key="'comm' + index">
                <p>
                  <span>{{ item.created | moment }}</span>
                  在<router-link
                    class="jie-title"
                    :to="{ name: 'detail', params: { tid: item._id } }"
                    >{{ item.title }}</router-link
                  >中回答
                </p>
                <div v-richtext="item.content"></div>
              </li>
              <div
                class="fly-none"
                style="min-height: 50px; padding: 30px 0; height: auto"
                v-if="comm.length === 0"
              >
                <span>没有回答任何问题</span>
              </div>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getHomeList } from '@/api/user'
export default {
  name: 'user-home',
  data () {
    return {
      uid: this.$route.params.uid,
      lists: [],
      comm: '',
      user: []

    };
  },
  components: {},
  computed: {},
  mounted () {
    this.getHome()
  },
  methods: {
    getHome () {
      getHomeList({ uid: this.uid }).then((res) => {
        if (res.code === 200) {
          this.user = new Array(res.data)
          console.log(this.user.roles === 'admin');
          this.comm = res.comments
          this.lists = res.list
        }
      })
    }
  }
}

</script>
<style scoped lang='scss' >
</style>